// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/patrol/api/PatrolApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/patrol/model/PatrolPlanIBListReq'
import OneClass from '@api/patrol/model/PatrolPlanIBDetailReq'
import InfoClass from '@api/patrol/model/FileReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询巡更报表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'patrolPlanIBList', DTO)
    return [resp.comQuery.totalCount, resp.list || []]
  },
  transList(arr) {
    arr.forEach((item) => {
      item.id = item.planId
      item.taskResult = item.status
    })
    return arr
  },

  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne(one, TIP = '查询巡更详情') {
    const DTO = CORE.grpcDTO(OneClass, { planId: one.id })
    const resp = await CORE.grpc(TIP, CLIENT, 'patrolPlanIBDetail', DTO)
    return resp
  },
  transOne(obj, { state: { one } }) {
    obj.id = obj.planId
    obj.status = obj.status || one.status
    return obj
  },

  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(infoParam, TIP = '查询巡更点图片') {
    const DTO = CORE.grpcDTO(InfoClass, infoParam)
    const resp = await CORE.grpc(TIP, CLIENT, 'file', DTO)
    return resp.url || []
  },
}
